package thermologic.gui;

import javax.swing.table.AbstractTableModel;
import thermologic.core.Datalogger;


/**
 *
 * @author mrivadeneira
 */
public class TraceDataModel extends AbstractTableModel
{
    protected static final int NUM_ROWS = 4;
    protected static final int NUM_COLS = 2;
    
    private Datalogger datalogger;
    private String[] colHeaders;
    private String[] paramNames;
    
    public TraceDataModel()
    {
        colHeaders = new String[NUM_COLS];
        
        colHeaders[0] = java.util.ResourceBundle.getBundle("properties/language").
                            getString("thermologic.traceTable.col1");
        
        colHeaders[1] = java.util.ResourceBundle.getBundle("properties/language").
                            getString("thermologic.traceTable.col2");
        
        paramNames = new String[] {
                java.util.ResourceBundle.getBundle("properties/language").
                        getString("thermologic.traceTable.param1"),
                        
                java.util.ResourceBundle.getBundle("properties/language").
                        getString("thermologic.traceTable.param2"),
                        
                java.util.ResourceBundle.getBundle("properties/language").
                        getString("thermologic.traceTable.param3"),
                        
                java.util.ResourceBundle.getBundle("properties/language").
                        getString("thermologic.traceTable.param4")
            };
    }
    
    public void setDatalogger(Datalogger d)
    {
        if(d == null)
        {
            throw new IllegalArgumentException("Parameter datalogger is null");
        }
        this.datalogger = d;
    }
    
    public int getRowCount()
    {
        return NUM_ROWS;
    }

    public int getColumnCount()
    {
        return NUM_COLS;
    }
    
    @Override
    public String getColumnName(int col)
    {
        return colHeaders[col];
    }

    public Object getValueAt(int row, int col)
    {
        String ret = "";
        
        if(col == 0)
        {
            ret = paramNames[row];
        }
        else if(col == 1)
        {
            if(datalogger != null)
            {
                switch(row)
                {
                    case 0: ret = datalogger.getId();
                            break;
                    
                    case 1: ret = datalogger.getDeviceType().getName();
                            break;
                    
                    case 2: ret = datalogger.getDescription();
                            break;
                            
                    case 3: ret = datalogger.getStatus().toString();
                            break;
                }
            }
        }
        
        return ret;
    }

}
